package com.zhaolixiang.view.draw2

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.view.View
import android.graphics.Typeface



/**
 * Created by Administrator on 2018/1/1.
 */
class PaintView(context: Context):View(context) {
    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
        //设置画笔
        val paint=Paint();
        //设置是否抗拒
        paint.isAntiAlias=true
        //设置颜色
        paint.color= Color.parseColor("#448ced")
        //设置宽度
        paint.strokeWidth=5f
        //设置文本大小
        paint.textSize=80f
     /*   //设绘图样式
        paint.style=Paint.Style.STROKE
        //设置文字对其方式
        paint.textAlign=Paint.Align.CENTER



    */

        val str="千秋万代小马哥"
        paint.style=Paint.Style.FILL
        canvas.drawText(str,10f,100f,paint)
        paint.style=Paint.Style.FILL_AND_STROKE
        canvas.drawText(str,10f,200f,paint)
        paint.style=Paint.Style.STROKE
        canvas.drawText(str,10f,300f,paint)


        //设置是否为粗体
        paint.isFakeBoldText=true
        //设置下划线
        paint.isUnderlineText=true
        //设置带下删除线效果
        paint.isStrikeThruText=true

        paint.style=Paint.Style.FILL


        //设置字体水平倾斜度，普通字体倾斜度为-0,25
        paint.textSkewX=-0.25f
        canvas.drawText(str,10f,400f,paint)
        //设置字体水平倾斜度，普通字体倾斜度为-0,25
        paint.textSkewX=0.25f
        canvas.drawText(str,10f,500f,paint)

        //只会水平拉伸，高度不变
        paint.textScaleX=2f
        canvas.drawText(str,10f,500f,paint)


        val paint2 = Paint()
        paint2.color = Color.RED  //设置画笔颜色

        paint2.strokeWidth = 5f//设置画笔宽度
        paint2.isAntiAlias = true //指定是否使用抗锯齿功能，如果使用，会使绘图速度变慢
        paint2.textSize = 80f//设置文字大小
        paint2.style = Paint.Style.FILL//绘图样式，设置为填充

        val pos = floatArrayOf(80f, 100f, 80f, 200f, 80f, 300f, 80f, 400f)
        canvas.drawPosText("画图示例", pos, paint2)//两个构造函数

        val familyName = "宋体"
        val font = Typeface.create(familyName, Typeface.NORMAL)
        paint.typeface = font
        canvas.drawText("宋体", 10f, 600f, paint)


    }
}